<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
#parse("/WEB-INF/views_webapp/layout/css.html")
<title>咕哒猎人-钉钉</title>
<style type="text/css">
#addMore{
	display: block;
	width: auto;
	height: 10rem;
	text-align: center;
	line-height: 10rem;
	border: 1px dashed #eee;
	margin: 0 0.5rem 0 0.5rem;
	background: #f5f5f5;
	border-radius: 4px;
}

</style>
</head>
<body>
	<div class="wrapper">
		<div id="foodbox">
			<div class="foodinfo">
				<img src="${base}/static/res/webapp/img/1.jpg" class="img" />
				<img src="${base}/static/res/webapp/img/1.jpg" class="img" />
				<div class="foodtitle">
					好吃的零食-北田早迷香-200g
				</div>
				<div class="food_fee">
					<span class="ff-1">每周特惠</span>
					<span class="ff-2">￥10.00</span>
<!-- 					<span class="ff-3">原价：500.00</span> -->
				</div>
			</div>
		</div>
	</div>
	
	<div class="goumai" style="height:27rem">
		<br>
		<br>
		<br>
		<div class="allfee">
		<div style="padding-left:10px;padding-right:10px;">&nbsp;&nbsp;&nbsp;&nbsp;欢迎您：<div id="userName" style="display:inline-block;font-weight:bold"></div>&nbsp;成为钉钉ISV，您当前在钉钉的<code>userId</code>为：
		<div id="userId" style="display:inline-block;font-weight:bold"></div> 。</div>
			共需要支付：￥<span id="feecount">10.00</span>
		</div>
		${config}
		<a class="goumaibtn" style="width:40%;height: 3rem;line-height: 3rem;" onclick="scan()">继续扫一扫</a>
		<br>
		<a id="goumaibtn" style="width:40%;height: 3rem;line-height: 3rem;">立刻购买</a>
	</div>
#parse("/WEB-INF/views_webapp/layout/bottom.html")
<script id="item-tpl" type="text/html">
	<div class="foodinfo">
		<img src="${base}/static/res/webapp/img/1.jpg" class="img" />
		<div class="foodtitle">
			好吃的零食-北田早迷香-200g
		</div>
		<div class="food_fee">
			<span class="ff-1">每周特惠</span>
			<span class="ff-2">￥10.00</span>
		</div>
	</div>
</script>


<script type="text/javascript">
var _config = ${config};
</script>
<script type="text/javascript" src="http://g.alicdn.com/ilw/ding/0.7.3/scripts/dingtalk.js" ></script>
<script type="text/javascript">
window.addEventListener('load', function() {
	setTimeout(function(){
	}, 500);
});
	dd.config({
		agentId : _config.agentid,
		corpId : _config.corpId,
		timeStamp : _config.timeStamp,
		nonceStr : _config.nonceStr,
		signature : _config.signature,
		jsApiList : [ 'runtime.info', 'biz.contact.choose',
				'device.notification.confirm', 'device.notification.alert',
				'device.notification.prompt', 'biz.ding.post',
				'biz.util.openLink' ]
	});


	dd.ready(function() {
		 alert('dd.ready rocks!');

		dd.runtime.info({
			onSuccess : function(info) {
				alert('runtime info: ' + JSON.stringify(info));
			},
			onFail : function(err) {
				alert('fail: ' + JSON.stringify(err));
			}
		});
		/* dd.ui.pullToRefresh.enable({
		    onSuccess: function() {
		    },
		    onFail: function() {
		    }
		}) */

		dd.runtime.permission.requestAuthCode({
			corpId : _config.corpId,
			onSuccess : function(info) {
				alert('authcode: ' + info.code);
				$.ajax({
					url : 'userinfo?code=' + info.code + '&corpid='
							+ _config.corpId,
					type : 'GET',
					success : function(data, status, xhr) {
						alert("----");
						var info = JSON.parse(data);

						document.getElementById("userName").innerHTML = info.name;
						document.getElementById("userId").innerHTML = info.userid;

					},
					error : function(xhr, errorType, error) {
						//logger.e("yinyien:" + _config.corpId);
						alert(errorType + ', ' + error);
					}
				});

			},
			onFail : function(err) {
				alert('fail: ' + JSON.stringify(err));
			}
		});
		
		dd.biz.user.get({
	        onSuccess: function (info) {
	            logger.e('userGet success: ' + JSON.stringify(info));
	        },
	        onFail: function (err) {
	            logger.e('userGet fail: ' + JSON.stringify(err));
	        }
	    });
	});

	dd.error(function(err) {
		alert('dd error: ' + JSON.stringify(err));
	});

	$(function(){
		//购买
		$("#goumaibtn").click(function(){
			$.ui.mask("客官稍等……");
			//执行提交逻辑
			window.location.href="${base}/gd/pay";
		});
	});
	
	function scan(){
		try{
			dd.biz.util.scan({
			    type: "qrCode",//type为qrCode或者barCode
			    onSuccess: function(data) {
			    //onSuccess将在扫码成功之后回调
			      /* data结构
			        { 'text': String}
			      */
			      //alert(data.text);
			      var _tpl=template("item-tpl",{});
		    		document.getElementById("foodbox").insertAdjacentHTML("beforeBegin", _tpl);
		    		//更新总价
		    		var nowCount=$("#feecount").html();
		    		$("#feecount").html(parseFloat(nowCount)+10.00)
			    },
			   onFail : function(err) {
		   	   		alert("----");
			   }
			})
		}catch(e){
			alert("init scan qrCode error");
		}
	}
</script>
</body>
</html>